//
//  ViedoListViewController.m
//  Leisure
//
//  Created by xalo on 16/7/4.
//  Copyright © 2016年 Hero. All rights reserved.
//

#import "ViedoListViewController.h"

@interface ViedoListViewController ()<UITableViewDataSource,UITableViewDelegate>
@property (weak, nonatomic) IBOutlet UITableView *tableView;
@property (nonatomic,strong)NSMutableArray *dataSource;
@end

@implementation ViedoListViewController
- (NSMutableArray *)dataSource{
    if (!_dataSource) {
        _dataSource = [[NSMutableArray alloc]init];
    }
    return _dataSource;
}

- (void)viewDidLoad {
    [super viewDidLoad];
   
    self.navigationItem.title = self.backTitle;
    [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cell"];
    
    
    UIImageView *headeView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, kWidth, kHeight/5*2)];
    headeView.backgroundColor = [UIColor cyanColor];
  
    
    [RequestManager fetchDataWithUrl:kViedoListURL parameter:@{@"radioid":self.radionID} mehtod:@"POST" compelet:^(NSData *data) {
        NSDictionary *bigDic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:nil];
        NSLog(@"%@",bigDic);
        
        [headeView sd_setImageWithURL:[NSURL URLWithString:bigDic[@"data"][@"radioInfo"][@"coverimg"]]];
        
        for (NSDictionary *smallDic in bigDic[@"data"][@"list"]) {
            ViedoDetailModel *model = [[ViedoDetailModel alloc]init];
            [model setValuesForKeysWithDictionary:smallDic];
            [self.dataSource addObject:model];
            
        }
        
    } updata:^{
        self.tableView.tableHeaderView = headeView;
        [self.tableView reloadData];
        
    }];
    
}
#pragma mark----------tableViewDelegate-----------
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.dataSource.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
    cell.textLabel.text = [self.dataSource[indexPath.row] title];
    
    return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    ViedoPlayViewController *play = [ViedoPlayViewController sharedManager];
    
    play.index      = indexPath.row;
    play.dataSource = self.dataSource;
    [self.navigationController pushViewController:play animated:YES];

}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
